using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AttackDownward : KoishiEffect
{
    public Attack attack;
    public ButtonInput buttonInput;

    public int reboundSpeed = 8;

    void Start()
    {
        attack = owner.gameObject.GetComponent<Attack>();
        buttonInput = owner.gameObject.GetComponent<ButtonInput>();
    }

    void Update()
    {
        MoveWithOwner();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("enemy"))
        {
            Rebound();
            attack.HarmEnemy(collision);
        }

        if (collision.gameObject.CompareTag("sharpGround"))
        {
            Rebound();
        }
    }

    private void Rebound()
    {
        if(buttonInput.canControl) owner.speed.y = reboundSpeed;
        owner.speed.x *= 0.2f;
        buttonInput.AirMoveRecover();
    }
}
